package cool.mtc.minghe.web.controller.websocket;

import cool.mtc.minghe.web.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author 明河
 */
@Tag(name = "WebSocket")
@RestController
@RequestMapping("/api/ws")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class WebSocketController extends BaseController {

    @Tag(name = "WebSocket")
    @Operation(summary = "获取ChatId")
    @GetMapping("chat_id")
    public String getChatId() {
        return UUID.randomUUID().toString().replace("-", "").toUpperCase();
    }

    @MessageMapping("/hello")
    @SendTo("/topic/hello")
    public String hello(String msg) {
        return msg;
    }
}
